﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using BeatEmUp.Characters;
using BeatEmUp.Movement;
using BeatEmUp.Animation;
namespace BeatEmUp
{
    class MovementManager : MovementAbstr
    {
        public MovementManager(Rectangle rectangle) :
            base(rectangle)
        {
            move = 5;
        }

        public void DoSomeMovement(KeyboardState keyboardState, GamePadState gamePadState,GameTime gameTime, AnimationManager am)
        {
            if (keyboardState.IsKeyDown(Keys.Up) ||
                gamePadState.IsButtonDown(Buttons.LeftThumbstickUp) ||
                gamePadState.IsButtonDown(Buttons.DPadUp))
            {
                am.UpdateFrame(gameTime);
                if (!MovementBoundaries.ExceedsBoundaries(new Rectangle(position.X, position.Y - move, position.Width, position.Height)))
                    Move(MoveEnum.Up);
            }
            if (keyboardState.IsKeyDown(Keys.Down) ||
                gamePadState.IsButtonDown(Buttons.LeftThumbstickDown) ||
                gamePadState.IsButtonDown(Buttons.DPadDown))
            {
                am.UpdateFrame(gameTime);
                if (!MovementBoundaries.ExceedsBoundaries(new Rectangle(position.X, position.Y + move, position.Width, position.Height)))
                    Move(MoveEnum.Down);
                else
                    position.Y = 768 - position.Height;
                //position.Y = MovementBoundaries.gameField.Y + MovementBoundaries.gameField.Height - position.Height;
            }
            if (keyboardState.IsKeyDown(Keys.Left) ||
                gamePadState.IsButtonDown(Buttons.LeftThumbstickLeft) ||
                gamePadState.IsButtonDown(Buttons.DPadLeft))
            {
                am.UpdateFrame(gameTime);
                if (!MovementBoundaries.ExceedsBoundaries(new Rectangle(position.X - move, position.Y, position.Width, position.Height)))
                    Move(MoveEnum.Left);
                else
                    position.X = MovementBoundaries.gameField.X;
            }
            if (keyboardState.IsKeyDown(Keys.Right) ||
                gamePadState.IsButtonDown(Buttons.LeftThumbstickRight) ||
                gamePadState.IsButtonDown(Buttons.DPadRight))
            {
                am.UpdateFrame(gameTime);
                if (!MovementBoundaries.ExceedsBoundaries(new Rectangle(position.X + move, position.Y, position.Width, position.Height)))
                    Move(MoveEnum.Right);
                else
                    position.X = 1024 - position.Width;
            }
        }
    }
}
